#include "Entity.h"

void Entity::draw(Viewport *vp)
{
	float drawX = (this->x - this->texOffsetX);
	float drawY = (this->y - this->texOffsetY);
	
	Vector2 drawPoint = vp->gameworldToScreen(drawX, drawY);
	
	
	al_draw_scaled_bitmap(texture, 0.0f, 0.0f, this->texWidth, this->texHeight, drawPoint.x, drawPoint.y, this->texWidth * vp->getZoom(), this->texHeight * vp->getZoom(), 0);
	if (this->selected)
		al_draw_rectangle(drawX - 5.0f, drawY - 5.0f, drawX + this->texWidth + 5.0f,  drawY + this->texHeight + 5.0f, al_map_rgb(255,0,0), 2.0f);
}

void Entity::update(void)
{

}

void Entity::init(char *texturePath, std::string name, int texOffsetX, int texOffsetY)
{
	this->name = name;

	this->texture = al_load_bitmap(texturePath);
	this->texWidth = al_get_bitmap_width(texture);
	this->texHeight = al_get_bitmap_height(texture);
	this->texOffsetX = texOffsetX;
	this->texOffsetY = texOffsetY;

	this->selected = false;
	this->selectable = true;
	this->selectableMulti = true;

	this->x = 0;
	this->y = 0;
}

Entity::Entity(char *texturePath, std::string name)
{
	init(texturePath, name, 0, 0);
}

Entity::Entity(char *texturePath, std::string name, int texOffsetX, int texOffsetY)
{
	init(texturePath, name, texOffsetX, texOffsetY);
}

//copy constructor
Entity::Entity(const Entity &ent)
{
	this->texture = ent.texture;
	this->texWidth = ent.texWidth;
	this->texHeight = ent.texHeight;
	this->texOffsetX = ent.texOffsetX;
	this->texOffsetY = ent.texOffsetY;

	this->selected = ent.selected;
	this->selectable = ent.selectable;
	this->selectableMulti = ent.selectableMulti;

	this->x = ent.x;
	this->y = ent.y;
}

Entity::~Entity(void)
{
	if (texture != NULL)
		al_destroy_bitmap(texture);
}
